﻿package mortal.game.view.rebate.openServerSevenDay.panel
{
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.rebate.data.*;
    import mortal.game.view.rebate.item.*;
    import mortal.game.view.rebate.openServerSevenDay.data.*;
    import mortal.game.view.rebate.rank.*;
    import mortal.mvc.core.*;

    public class OpenServerSevenDayBottom extends GSprite
    {
        protected var _rightBg:GImageBitmap;
        protected var _rightScBg:ScaleBitmap;
        protected var _leftBg:GImageBitmap;
        protected var _firstBg:GBitmap;
        protected var _firstTitle:GBitmap;
        protected var _items1:CellsGridSprite;
        protected var _playerDes:GBitmap;
        protected var _playerName:GTextFiled;
        protected var _btn2:GLoadingButton;
        protected var _towThreeTitle:GBitmap;
        protected var _tip2:GTextFiled;
        protected var _items2:CellsGridSprite;
        protected var _tipTitle2:GBitmap;
        protected var _btn3:GLoadingButton;
        protected var _tip3:GTextFiled;
        protected var _items3:CellsGridSprite;
        protected var _rantTIP:GBitmap;
        protected var _btnGet4:GLoadingButton;
        protected var _items4:CellsGridSprite;
        protected var tip4:GTextFiled;
        protected var _line1:GBitmap;
        protected var _roleBg:GImageBitmap;
        protected var _tip1:GTextFiled;
        protected var _avatar:GImageBitmap;
        protected var _rangTipTxt:GTextFiled;
        protected var _detailBtn:GButton;
        protected var _tipButton:GTextFiled;
        protected var _line2:ScaleBitmap;
        protected var _line3:ScaleBitmap;
        public var rankPanel:RebateRankPanel;
        private var _info:Object;

        public function OpenServerSevenDayBottom()
        {
            this._info = {};
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._rightBg = UIFactory.gImageBitmap(ImagesConst.OpenServerSevenDayBgNumOne, 331, 0, null, this.onRbgLoadHd);
            this._rightScBg = UIFactory.bg(331, -1, 555, 254, this, ImagesConst.PanelBg);
            this._leftBg = UIFactory.gImageBitmap(ImagesConst.OpenServerSevenDayBgNumOne, 0, 0, this);
            this._firstBg = UIFactory.gBitmap(ImagesConst.OpenServerSevenDayNumOneBg, 0, 24, this);
            this._firstTitle = UIFactory.gBitmap(ImagesConst.OpenServerSevenDayNumOne, 82, 12, this);
            this._items1 = UIFactory.getUICompoment(CellsGridSprite);
            this._items1.colNum = 2;
            this._items1.vCellWid = 73;
            this._items1.hCellWid = 73;
            this._items1.genCellFun = this.genItem;
            this._items1.genCells(4);
            this._items1.x = 156;
            this._items1.y = 62;
            this.addChild(this._items1);
            this._playerDes = UIFactory.gBitmap(ImagesConst.OpenServerSevenDayPlayerName, 21, 52, this);
            this._playerName = UIFactory.gTextField("", 10, 70, 140, 30, this, GlobalStyle.textFormatPutong.setColor(16777215).setSize(15).center().setBold(true));
            this._btn2 = UIFactory.gLoadingButton(ImagesConst.LineOffCopyCellBtn_upSkin, 739, 30, 69, 25, this);
            this._btn2.label = "";
            this._towThreeTitle = UIFactory.gBitmap(ImagesConst.OpenServerSevenDay23, 360, 26, this);
            this._tip2 = UIFactory.gTextField("" + Language.getString(71862), 746, 30, 100, 20, this, GlobalStyle.textFormatLv.setSize(13).setBold(true));
            this._items2 = UIFactory.getUICompoment(CellsGridSprite);
            this._items2.colNum = 3;
            this._items2.vCellWid = 80;
            this._items2.hCellWid = 100;
            this._items2.genCellFun = this.genItem;
            this._items2.genCells(3);
            this._items2.x = 470;
            this._items2.y = 8;
            this.addChild(this._items2);
            this._tipTitle2 = UIFactory.gBitmap(ImagesConst.OpenServerSevenDay410, 359, 106, this);
            this._btn3 = UIFactory.gLoadingButton(ImagesConst.LineOffCopyCellBtn_upSkin, 739, 115, 70, 25, this);
            this._btn3.label = "";
            this._tip3 = UIFactory.gTextField("" + Language.getString(71862), 748, 116, 100, 20, this, GlobalStyle.textFormatLv.setSize(13).setBold(true));
            this._items3 = UIFactory.getUICompoment(CellsGridSprite);
            this._items3.colNum = 3;
            this._items3.vCellWid = 80;
            this._items3.hCellWid = 100;
            this._items3.genCellFun = this.genItem;
            this._items3.genCells(3);
            this._items3.x = 470;
            this._items3.y = 89;
            this.addChild(this._items3);
            this._rantTIP = UIFactory.gBitmap(ImagesConst.OpenServerSevenDay410, 355, 189, this);
            this._btnGet4 = UIFactory.gLoadingButton(ImagesConst.LineOffCopyCellBtn_upSkin, 739, 201, 70, 25, this);
            this._btnGet4.label = "" + Language.getString(71863);
            this._items4 = UIFactory.getUICompoment(CellsGridSprite);
            this._items4.colNum = 3;
            this._items4.vCellWid = 80;
            this._items4.hCellWid = 100;
            this._items4.genCellFun = this.genItem;
            this._items4.genCells(3);
            this._items4.x = 470;
            this._items4.y = 172;
            this.addChild(this._items4);
            this.tip4 = UIFactory.gTextField("" + Language.getString(71862), 748, 201, 100, 20, this, GlobalStyle.textFormatLv.setSize(13).setBold(true));
            this._line1 = UIFactory.gBitmap(ImagesConst.SplitLine4, 7, 215, this);
            this._roleBg = UIFactory.gImageBitmap(ImagesConst.ChatRoleHeadBg, 25, 116, this);
            this._tip1 = UIFactory.gTextField("" + Language.getString(71864), 14, 222, 250, 25, this, GlobalStyle.textFormatHuang.setSize(15).setBold(true));
            this._avatar = UIFactory.gImageBitmap("", 26, 99);
            this._rangTipTxt = UIFactory.gTextField("", 345, 197, 100, 25, this, GlobalStyle.textFormatLv.setSize(15).center().setBold(true));
            this._detailBtn = UIFactory.gButton("" + Language.getString(71865), 570, 253, 100, 22, this, "GreenLinkButton");
            this._tipButton = UIFactory.gTextField("" + Language.getString(71866), 203, 253, 341, 20, this, GlobalStyle.textFormatPutong.setSize(13));
            this._line2 = UIFactory.bg(350, 83, 518, 1, this, ImagesConst.SplitLine4);
            this._line3 = UIFactory.bg(349, 166, 517, 1, this, ImagesConst.SplitLine4);
            this._rightBg.visible = false;
            this._rantTIP.visible = false;
            var _loc_1:Boolean = false;
            this._rangTipTxt.mouseEnabled = false;
            this._rangTipTxt.selectable = _loc_1;
            var _loc_1:Boolean = false;
            this._tip1.mouseEnabled = false;
            var _loc_1:* = _loc_1;
            this._tip1.selectable = _loc_1;
            var _loc_1:* = _loc_1;
            this._tip2.mouseEnabled = _loc_1;
            this._tip2.selectable = _loc_1;
            var _loc_1:Boolean = false;
            this._tip3.mouseEnabled = false;
            this._tip3.selectable = _loc_1;
            this.tip4.visible = false;
            var _loc_1:Boolean = false;
            this.tip4.selectable = false;
            this.tip4.mouseEnabled = _loc_1;
            this._btnGet4.configEventListener(MouseEvent.CLICK, this.onGet);
            this._btnGet4.enabled = false;
            this._btn2.configEventListener(MouseEvent.CLICK, this.onTipCk);
            this._btn3.configEventListener(MouseEvent.CLICK, this.onTipCk);
            this._detailBtn.configEventListener(MouseEvent.CLICK, this.onShowRank);
            return;
        }// end function

        private function loadRes() : void
        {
            return;
        }// end function

        private function onRbgLoadHd() : void
        {
            var _loc_3:ScaleBitmap = null;
            var _loc_1:* = ResourceConst.getRectangle(ImagesConst.OpenServerSevenDayBgNumOne);
            var _loc_2:* = this._rightBg.bitmapData;
            if (_loc_2 != null)
            {
                _loc_3 = UICompomentPool.getUICompoment(ScaleBitmap) as ScaleBitmap;
                _loc_3.bitmapData = _loc_2.clone();
                _loc_3.createDisposeChildren();
                _loc_3.scale9Grid = scale9Grid;
                this._rightScBg = _loc_3;
                UIFactory.setObjAttri(this._rightScBg, 330, 0, 555, 254);
                this.addChildAt(this._rightScBg, 0);
            }
            return;
        }// end function

        private function onTipCk(event:MouseEvent) : void
        {
            MsgManager.showRollTipsMsg("" + Language.getString(71867));
            return;
        }// end function

        private function onShowRank(event:MouseEvent) : void
        {
            if (this.rankPanel == null)
            {
                this.rankPanel = UIFactory.getUICompoment(RebateRankPanel);
            }
            this.rankPanel.show();
            this.rankPanel.getByDayNum(this._info.dayNum);
            return;
        }// end function

        private function genItem() : RebateItem
        {
            var _loc_1:* = UIFactory.getUICompoment(RebateItem);
            return _loc_1;
        }// end function

        private function onGet(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RebateOpenServerSevenDayGetReward, this._info));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            EffectManager.glowFilterUnReg(this._btnGet4);
            this._rightBg = null;
            this._rightScBg = null;
            this._leftBg = null;
            this._firstBg = null;
            this._firstTitle = null;
            this._items1 = null;
            this._playerDes = null;
            this._playerName = null;
            this._btn2 = null;
            this._towThreeTitle = null;
            this._tip2 = null;
            this._items2 = null;
            this._tipTitle2 = null;
            this._btn3 = null;
            this._tip3 = null;
            this._items3 = null;
            this._rantTIP = null;
            this._btnGet4 = null;
            this._items4 = null;
            this.tip4 = null;
            this._line1 = null;
            this._roleBg = null;
            this._tip1 = null;
            this._avatar = null;
            this._rangTipTxt = null;
            this._detailBtn = null;
            this._tipButton = null;
            this._line2 = null;
            this._line3 = null;
            this.rankPanel = null;
            LoaderHelp.removeResEvent(ResFileConst.chatPrivate, this.loadRes);
            return;
        }// end function

        public function updateBottomByDayNum(param1:int) : void
        {
            this._info.dayNum = param1;
            this.updateRewards();
            this.updateGetBtn();
            return;
        }// end function

        public function updateRole(param1:SToplist, param2:int) : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            this.clear();
            if (param1)
            {
                _loc_3 = param1.propertyThree;
                _loc_4 = param1.propertyTwo;
                if (!this._avatar)
                {
                    this._avatar = UIFactory.gImageBitmap("", 26, 99, this);
                }
                this._avatar.imgUrl = AvatarUtil.getPlayerAvatarUrl(_loc_3, _loc_4, AvatarUtil.Big);
                switch(param2)
                {
                    case EToplistType._EToplistTypePlayerLevel:
                    case EToplistType._EToplistTypePlayerCombat:
                    {
                        this._playerName.text = "" + param1.entityName;
                        break;
                    }
                    default:
                    {
                        this._playerName.text = "" + param1.ownerName;
                        break;
                        break;
                    }
                }
            }
            return;
        }// end function

        private function clear() : void
        {
            if (this._avatar)
            {
                this._avatar.dispose();
                this._avatar = null;
            }
            this._playerName.text = "" + Language.getString(71868);
            return;
        }// end function

        public function updateRewards() : void
        {
            var _loc_6:CellsGridSprite = null;
            var _loc_7:Array = null;
            var _loc_8:int = 0;
            var _loc_9:RebateItem = null;
            var _loc_10:SPlayerItem = null;
            var _loc_1:* = this._info.dayNum;
            var _loc_2:* = OpenServerSevenDayUtil.getRewardsByDay(_loc_1);
            if (_loc_2 == null)
            {
                return;
            }
            var _loc_3:* = _loc_2[0];
            var _loc_4:int = 0;
            while (_loc_4 < _loc_3.length)
            {
                
                _loc_6 = this["_items" + (_loc_4 + 1)] as CellsGridSprite;
                if (_loc_6)
                {
                    _loc_7 = _loc_3[_loc_4];
                    _loc_6.genCells(_loc_7.length);
                    _loc_8 = 0;
                    while (_loc_8 < _loc_7.length)
                    {
                        
                        _loc_9 = _loc_6.cellArr[_loc_8];
                        _loc_10 = _loc_7[_loc_8];
                        if (_loc_9)
                        {
                            _loc_9.updateInfo(_loc_10);
                        }
                        _loc_8++;
                    }
                }
                _loc_4++;
            }
            var _loc_5:* = _loc_2[1];
            this.updateTargetLevel(_loc_1, _loc_5);
            return;
        }// end function

        private function updateTargetLevel(param1:int, param2:Object) : void
        {
            var _loc_3:String = "";
            if (param1 == 99)
            {
                _loc_3 = "" + Language.getString(71869);
                this._rangTipTxt.text = _loc_3 + "" + Language.getString(71871);
            }
            else if (param1 == 100)
            {
                _loc_3 = "" + Language.getString(71870);
                this._rangTipTxt.text = _loc_3 + "" + Language.getString(71871);
            }
            else
            {
                _loc_3 = "" + Cache.instance.openServerSevenDay.getNameByDay(this._info.dayNum);
                this._rangTipTxt.text = Language.getStringByParam(71872, _loc_3, param2.targetLevel);
            }
            return;
        }// end function

        public function updateGetBtn() : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_1:* = Cache.instance.openServerSevenDay.canGet;
            var _loc_2:* = this._info.dayNum;
            if (_loc_2 == 99 || _loc_2 == 100)
            {
                this._btnGet4.enabled = false;
                this._btnGet4.visible = false;
                this.tip4.visible = true;
            }
            else
            {
                this.tip4.visible = false;
                this._btnGet4.visible = true;
                _loc_3 = RebateUtil.getTargetType();
                _loc_4 = Cache.instance.openServerSevenDay.dayNumToCfgTargetType[_loc_2];
                if (_loc_4 == _loc_3)
                {
                    _loc_5 = this.dayCanGet();
                    if (_loc_5 == 1)
                    {
                        this.setGetBtn(true);
                        this._btnGet4.label = "" + Language.getString(71873);
                    }
                    else if (_loc_5 == 2)
                    {
                        this.setGetBtn(false);
                        this._btnGet4.label = "" + Language.getString(71874);
                    }
                    else
                    {
                        this.setGetBtn(false);
                    }
                }
                else
                {
                    this.setGetBtn(false);
                }
            }
            return;
        }// end function

        private function dayCanGet() : int
        {
            var _loc_1:* = this._info.dayNum;
            var _loc_2:* = OpenServerSevenDayUtil.getRewardsByDay(_loc_1);
            if (_loc_2 == null)
            {
                return 0;
            }
            var _loc_3:* = _loc_2[(_loc_2.length - 1)];
            var _loc_4:* = Cache.instance.openServerSevenDay.result;
            return _loc_4[_loc_3.id];
        }// end function

        private function updateTipBtn(param1:int) : void
        {
            var _loc_2:int = 0;
            var _loc_3:Boolean = true;
            this._btn3.enabled = true;
            this._btn2.enabled = _loc_3;
            var _loc_3:* = "" + Language.getString(71875);
            this._tip3.text = "" + Language.getString(71875);
            this._tip2.text = _loc_3;
            var _loc_3:String = null;
            this._btn3.filters = null;
            this._btn2.filters = _loc_3;
            if (param1 == 99 || param1 == 100)
            {
            }
            else
            {
                _loc_2 = OpenServerSevenDayUtil.getOpenServerDayNum();
                if (_loc_2 > param1)
                {
                    var _loc_3:Boolean = false;
                    this._btn3.enabled = false;
                    this._btn2.enabled = _loc_3;
                    var _loc_3:* = [FilterConst.colorFilter2];
                    this._btn3.filters = [FilterConst.colorFilter2];
                    this._btn2.filters = _loc_3;
                    var _loc_3:* = "" + Language.getString(71876);
                    this._tip3.text = "" + Language.getString(71876);
                    this._tip2.text = _loc_3;
                }
            }
            return;
        }// end function

        private function setGetBtn(param1:Boolean) : void
        {
            if (param1)
            {
                this._btnGet4.enabled = true;
                this._btnGet4.filters = null;
                EffectManager.glowFilterReg(this._btnGet4);
            }
            else
            {
                EffectManager.glowFilterUnReg(this._btnGet4);
                this._btnGet4.enabled = false;
                this._btnGet4.filters = [FilterConst.colorFilter2];
            }
            return;
        }// end function

    }
}
